Reference:
http://en.wikipedia.org/wiki/Rotation_matrix



In linear algebra, a rotation matrix is a matrix that is used to perform a rotation in Euclidean space. For example the matrix
R =begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}
R =begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}

rotates points in the xy-Cartesian plane counterclockwise through an angle θ about the origin of the Cartesian coordinate system. To perform the rotation using a rotation matrix R, the position of each point must be represented by a column vectorv, containing the coordinates of the point. A rotated vector is obtained by using the matrix multiplication Rv. Since matrix multiplication always fixes the zero vector, rotation matrices can only be used to describe rotations that fix the origin.
Rotation matrices provide a simple algebraic description of such rotations, and are used extensively for computations ingeometry, physics, and computer graphics. These rotations can be in dimension 2, where they are determined by the angleθ of rotation, or in dimension 3, where in addition an axis of rotation is involved; the angle and axis are implicitly represented by the entries of the rotation matrix. The notion of rotation is not commonly used in dimensions higher than 3; there is a notion of a rotational displacement, which can be represented by a matrix, but no associated single axis or angle.
Rotation matrices are square matrices, with real entries. More specifically they can be characterized as orthogonal matriceswith determinant 1:
R^{T} = R^{-1}, det R = 1,
R^{T} = R^{-1}, det R = 1,
.

Rotations in two dimensions

external image 220px-Counterclockwise_rotation.pngexternal image magnify-clip.pngA counterclockwise rotation of a vector through angle θ. The vector is initially aligned with the x-axis.
In two dimensions every rotation matrix has the following form:
R(theta) = begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}
R(theta) = begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}
.
This rotates column vectors by means of the following matrix multiplication:
begin{bmatrix}x' \y' \end{bmatrix} = begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}begin{bmatrix}x \y \end{bmatrix}
begin{bmatrix}x' \y' \end{bmatrix} = begin{bmatrix}cos theta & -sin theta \sin theta & cos theta \end{bmatrix}begin{bmatrix}x \y \end{bmatrix}
.
So the coordinates (x',y') of the point (x,y) after rotation are:
x' = x cos theta - y sin theta,
x' = x cos theta - y sin theta,
,
y' = x sin theta + y cos theta,
y' = x sin theta + y cos theta,
.
The direction of vector rotation is counterclockwise if θ is positive (e.g. 90°), and clockwise if θ is negative (e.g. -90°).
R(-theta) = begin{bmatrix}cos theta & sin theta \-sin theta & cos theta \end{bmatrix},
R(-theta) = begin{bmatrix}cos theta & sin theta \-sin theta & cos theta \end{bmatrix},
.


Common rotations

Particularly useful are the matrices for 90° and 180° rotations:
R(90^circ) = begin{bmatrix}0 & -1 \[3pt]1 & 0 \end{bmatrix}
R(90^circ) = begin{bmatrix}0 & -1 \[3pt]1 & 0 \end{bmatrix}
(90° counterclockwise rotation)
R(180^circ) = begin{bmatrix}-1 & 0 \[3pt]0 & -1 \end{bmatrix}
R(180^circ) = begin{bmatrix}-1 & 0 \[3pt]0 & -1 \end{bmatrix}
(180° rotation in either direction – a half-turn)
R(270^circ) = begin{bmatrix}0 & 1 \[3pt]-1 & 0 \end{bmatrix}
R(270^circ) = begin{bmatrix}0 & 1 \[3pt]-1 & 0 \end{bmatrix}
(270° counterclockwise rotation, the same as a 90° clockwise rotation)